﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
 

namespace AMSReportBuildService
{
    class GetDataSetHelp
    {
         
        public  DataSet AssetDistributeData
        {
            get
            {
                const string sqlString = @"select b.Name ,count(*) count from dbo.AmsCore_AssetInfo a join dbo.Frame_UserGroup b on a.UserGroupId = b.Id 
                                    group by a.UserGroupId, b.Name";
                return DataAccess.GetData(sqlString);
            }
        }

        public  DataSet AssetDistributeByAreaData
        {
            get
            {
                const string sqlString = @"select area.Id AreaId,area.Name ,count(*) count from dbo.AmsCore_AssetInfo ai
 left outer join dbo.AmsCore_Site site on ai.SiteId = site.Id
 left outer join  dbo.AmsCore_Area area on site.AreaId = area.Id
   group by  area.Name,area.Id";
                return DataAccess.GetData(sqlString);
            }
        }

        public DataSet AssetValueDistributeData
        {
            get
            {
                const string sqlString = @"select b.Name ,sum(OriginalValue) value from dbo.AmsCore_AssetInfo a 
                                  join dbo.Frame_UserGroup b on a.UserGroupId = b.Id
                                  group by a.UserGroupId, b.Name";
                return DataAccess.GetData(sqlString);
            }
        }

        public DataSet AssetValueDistributeByAreaData
        {
            get
            {
                const string sqlString = @"select area.Id AreaId,area.Name ,sum(OriginalValue) value from dbo.AmsCore_AssetInfo ai
 left outer join dbo.AmsCore_Site site on ai.SiteId = site.Id
 left outer join  dbo.AmsCore_Area area on site.AreaId = area.Id
   group by  area.Name,area.Id";
                return DataAccess.GetData(sqlString);
            }
        }


        public static int GetAssetTotalCount()
        {
            int count = 0;
            string sql = "select count(*) from AmsCore_AssetInfo";
            var ds = DataAccess.GetData(sql);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                count = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
            }
            return count;
        }

        public static double GetAssetTotalValue()
        {
            double value = 0;
            string sql = "select sum(OriginalValue) from AmsCore_AssetInfo";
            var ds = DataAccess.GetData(sql);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                value = Convert.ToDouble(ds.Tables[0].Rows[0][0].ToString());
            }
            return value;
        }

 

    }
}
